package com.example.travelapplication.activity;

import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;

import com.example.travelapplication.R;
import com.example.travelapplication.fragment.FragmentAbout;
import com.example.travelapplication.fragment.FragmentInfo;
import com.example.travelapplication.fragment.FragmentOpen;

public class OptionActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_option);

        ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);

        Intent intent = getIntent();
        int position = intent.getIntExtra("position", -1);
        Log.d("flag", "" + position);

        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();

        FragmentInfo fragmentInfo = new FragmentInfo();
        FragmentOpen fragmentOpen = new FragmentOpen();
        FragmentAbout fragmentAbout = new FragmentAbout();

        switch (position){
            case 0:
                ft.replace(R.id.cl_container,fragmentInfo);
                actionBar.setTitle("个人信息");
                break;
            case 1:
                ft.replace(R.id.cl_container,fragmentOpen);
                actionBar.setTitle("开源");
                break;
            case 2:
                ft.replace(R.id.cl_container,fragmentAbout);
                actionBar.setTitle("关于");
                break;
        }
        ft.commit();  //提交
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                finish();
                break;
        }
        return super.onOptionsItemSelected(item);
    }
}